﻿@model MeetingFeedbackModel
@{
	Layout = null;
}
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<title>@Resources.HuiTongCIS</title>
	<link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.5/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.5/themes/icon.css" />
	@Styles.Render("~/Content/css")
	@Styles.Render("~/Content/stylecss")
	@Scripts.Render("~/bundles/modernizr")
	@Scripts.Render("~/bundles/jquery")
	<script type="text/javascript" charset="utf-8" src="~/Scripts/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="~/Scripts/jquery-easyui-1.4.5/locale/@ViewBag.EasyUiLanguage"></script>
	@Scripts.Render("~/bundles/common")
	<script type="text/javascript" charset="utf-8" src="~/Scripts/layer/layer.js"></script>
	<script type="text/javascript" src="~/Scripts/jquery-easyui-1.4.5/myjs.dialog.js"></script>
	<link rel="stylesheet" type="text/css" href="~/Content/Site.css" />
	<link rel="stylesheet" type="text/css" href="~/Content/Style.css" />
	<script type="text/javascript">
		$(function () {
			$(this).scrollTop(0);

			var language = "";
			@if (Request.Cookies["_culture"] == null) {
				<text>
				language = "@ConstValues.Language.Cn";
				</text>
			} else {
				<text>
				language = "@Request.Cookies["_culture"].Value";
				</text>
			}

			if (language == "@ConstValues.Language.Cn") {
				$("#cultureCn").css("background-color", "#c30d23");
				$("#cultureEn").css("background-color", "#7c7c7c");
				$("#hidCulture").val(language);
			} else {
				$("#cultureCn").css("background-color", "#7c7c7c");
				$("#cultureCn").css("borderRight", "0px");
				$("#cultureEn").css("background-color", "#c30d23");
				$("#hidCulture").val(language);
			}

			$("#hidQuizId").val("@Model.QuizId");
			$("#hidConferenceId").val("@Model.ConferenceId");
			$("#hidAttendenceId").val("@Model.AttendenceId");

			var url = "@Url.Action(nameof(MeetingFeedbackController.GetData),
					nameof(MeetingFeedbackController).GetControllerName())";

			$.get(url, null, function (data, textStatus, jqXHR) {
				var html = "";
				if (data.rows.length > 0) {
					var count = 0;
					var answer = 0;
					for (var index = 0; index < data.rows.length; index++) {
						var questionType = data.rows[index].questionType;
						var questionName = data.rows[index].questionName;
						if (index == 0) {
							if (questionType == "@ConstValues.QuestionType.单选题") {
								html += "<ul>@ConstValues.QuestionType.单选题：";
							} else if (questionType == "@ConstValues.QuestionType.多选题") {
								html += "<ul>@ConstValues.QuestionType.多选题：";
							} else {
								html += "<ul>@ConstValues.QuestionType.填空题：";
							}
							count = 1;
							answer = 1;
							html += "<li>";
							html += "<p>" + count + ". " + data.rows[index].questionName + "</p>";
						} else {
							if (questionName == data.rows[index - 1].questionName) {
								answer += 1;
							} else {
								count += 1;
								answer = 1;
								html += "</li><div class='clear'></div>";
								if (questionType != data.rows[index - 1].questionType) {
									if (questionType == "@ConstValues.QuestionType.单选题") {
										html += "</ul><ul>@ConstValues.QuestionType.单选题：";
									} else if (questionType == "@ConstValues.QuestionType.多选题") {
										html += "</ul><ul>@ConstValues.QuestionType.多选题：";
									} else {
										html += "</ul><ul>@ConstValues.QuestionType.填空题：";
									}
								}
								html += "<li>";
								html += "<p>" + count + ". " + data.rows[index].questionName + "</p>";
							}
						}

						if (questionType == "@ConstValues.QuestionType.单选题") {
							html += '<input type="radio" id="ans' + count + '_' + answer + '" name="' + count + '" style="margin-top:10px; display:inline-block;float:left;" />'
								+ '<span style="margin-top:10px; display:inline-block;float:left;">' + data.rows[index].answer + '</span>';
						} else if (questionType == "@ConstValues.QuestionType.多选题") {
							html += '<input type="checkbox" id="ans' + count + '_' + answer + '" name="' + count + '" style="margin-top:10px; display:inline-block;float:left;" />'
								+ '<span style="margin-top:10px; display:inline-block;float:left;">' + data.rows[index].answer + '</span>';
						} else {
							html += '<textarea id="ans' + count + '" style="margin-top:10px; height:50px; width:1130px;" />';
						}

						if (index == data.rows.length - 1) {
							html += "</li></ul>";
						}
					}
				}
				$("#ctnForm").html(html);
			});
		});

		function saveData() {
			var url = "@Url.Action(nameof(MeetingFeedbackController.GetData),
					nameof(MeetingFeedbackController).GetControllerName())";

			$.get(url, null, function (data, textStatus, jqXHR) {
				var model = {};
				model.quizId = $("#hidQuizId").val();
				model.conferenceId = $("#hidConferenceId").val();
				model.attendenceId = $("#hidAttendenceId").val();

				model.feedbackList = new Array();
				if (data.rows.length > 0) {
					var count = 0;
					var answer = 0;
					for (var index = 0; index < data.rows.length; index++) {
						var questionType = data.rows[index].questionType;
						var questionName = data.rows[index].questionName;
						if (index == 0) {
							count = 1;
							answer = 1;
						} else {
							if (questionName == data.rows[index - 1].questionName) {
								answer += 1;
							} else {
								count += 1;
								answer = 1;
							}
						}

						if (questionType == "@ConstValues.QuestionType.单选题") {
							if ($("#ans" + count + "_" + answer).prop("checked") == true) {
								model.feedbackList.push({
									questionId: data.rows[index].questionId,
									feedback: data.rows[index].answerId
								});
							}
						} else if (questionType == "@ConstValues.QuestionType.多选题") {
							if ($("#ans" + count + "_" + answer).prop("checked") == true) {
								model.feedbackList.push({
									questionId: data.rows[index].questionId,
									feedback: data.rows[index].answerId
								});
							}
						} else {
							if ($("#ans" + count).val().trim() != "") {
								model.feedbackList.push({
									questionId: data.rows[index].questionId,
									feedback: $("#ans" + count).val()
								});
							}
						}
					}
				}

				if (model.feedbackList.length == 0) {
					common.showError("@Resources.MsgOneFeedbackAtLeast");
				} else {
					$.messager.confirm("@Resources.Submit", "@Resources.CfmSave", function (r) {
						if (r) {
							var loading = layer.load(0, {
								shade: [0.4, "#fff"]
							});

							var token = $("#frmDetail").find('input[name="__RequestVerificationToken"]').eq(0).val();

							$.post("@Url.Action(nameof(MeetingFeedbackController.Submit),
									nameof(MeetingFeedbackController).GetControllerName())",
								{
									"__RequestVerificationToken": token,
									"model": model,
								},
								function (data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										setTimeout(function () {
											$(window.location).attr("href",
												"@Url.Action(nameof(AccountController.Login),
											nameof(AccountController).GetControllerName())");
										}, 2000);
									}
								}
							);
						}
					});
				}
			});
		}
	</script>
</head>
<body id="main">
	<div class="mar" style="position:relative;z-index:999">
		<div class="index">
			<!-- header start -->
			<div class="header02">
				<div class="t">
					<div class="fl"><img src="~/Images/homeImg/icon_01.png" align="absmiddle" width="16" />&nbsp;&nbsp;@Resources.Welcome@Resources.Vister&nbsp;&nbsp;</div>
					<div class="fl">
						<a href="javascript:void(0);" onclick="$(window.location).attr('href', '/Account/Login');">@Resources.Login</a>
						<a href="@Url.Action(nameof(RegisterController.Index),nameof(RegisterController).GetControllerName())">@Resources.Register</a>
					</div>
				</div>
				<div class="clear"></div>
			</div>
			<!-- header end -->
			<!-- container start -->
			<div class="container">
				<div class="fl"><img src="~/Images/homeImg/logo.png" /></div>
				<div class="fr mainmenu">
					<ul>
						<li><a href="@Url.Action(nameof(HomeController.Help),nameof(HomeController).GetControllerName())"><h3>@Resources.Help</h3></a></li>
						<li><a href="@Url.Action(nameof(HomeController.AboutUs),nameof(HomeController).GetControllerName())"><h3>@Resources.AboutUs</h3></a></li>
						<li><a href="@Url.Action(nameof(MeetingListLogoutController.Index),nameof(MeetingListLogoutController).GetControllerName())"><h3>@Resources.MeetingList</h3></a></li>
						<li><a href="@Url.Action(nameof(HomeController.Index),nameof(HomeController).GetControllerName())"><h3>@Resources.HomePage</h3></a></li>
					</ul>
				</div>
				<div class="clear"></div>
				<div class="rbox fl">
					<div id="right" style="width: 1200px;">
						<div class="con">
							<table style="width:100%;height:100% ">
								<tr>
									<td class="b4">
										<div class="c" style="width: 1200px;">
											<form id="frmDetail" method="post">
												@Html.AntiForgeryToken()
												<div class="index">
													<div class="info">
														<div class="tit" style="font-size:22px; text-align:center;">@Model.QuizName</div>
														<div class="feedback">
															<div id="ctnForm"></div>
															<input type="hidden" id="hidQuizId" />
															<input type="hidden" id="hidConferenceId" />
															<input type="hidden" id="hidAttendenceId" />
														</div>
													</div>
												</div>
											</form>
											<div class="btnDiv">
												<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Submit" />
											</div>
										</div>
									</td>
								</tr>
							</table>
						</div>
					</div>
				</div>
				<div class="clear"></div>
			</div>
			<!-- container end -->
		</div>
		<!-- footer start -->
		<div class="footer">
			<p>&copy;@Resources.CopyRightOfCisSystem</p>
			<p id="CopyRightId" style="margin-top:-70px">
				<a href="@Resources.CopyRightOfCisSystemLinkOne" target="_blank" style="color:#999">@Resources.CopyRightOfCisSystemOne &nbsp;&nbsp;</a>
				<a href="@Resources.CopyRightOfCisSystemLinkTwo" target="_blank" style="color:#999"><img src="~/Images/police.png" style="position:relative; top:4px;" />@Resources.CopyRightOfCisSystemTwo</a>
			</p>
		</div>
		<!-- footer end -->
	</div>
	<div class="fixedMessageContainer">
		<div class="fixedMessage fixedErrorMessage">
			<h2>Error!</h2>
			<p id="fixedErrorMessageContent"></p>
		</div>
		<div class="fixedMessage fixedSuccessMessage">
			<h2>Success!</h2>
			<p id="fixedSuccessMessageContent"></p>
		</div>
	</div>
</body>
</html>